package tech.heptagram.staff.model.enums;

import tech.heptagram.staff.exception.EnumParseException;

/**
 * @author daxiong
 * @date 2019/4/1
 */
public enum CityType {

    BEIJING(21, "北京"),
    SHANGHAI(22, "上海"),
    SHENZHEN(23, "广州"),
    GUANGZHOU(24, "深圳");

    private Integer value;
    private String desc;

    CityType(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public Integer getValue() {
        return this.value;
    }

    public String getDesc() {
        return this.desc;
    }

    public static Integer descOf(String desc){
        for (CityType type : CityType.values()) {
            if (type.getDesc().equals(desc)) {
                return type.getValue();
            }
        }
        return null;
    }

    public static CityType valueOf(Integer value) {
        for (CityType type : CityType.values()) {
            if (type.getValue() == value) {
                return type;
            }
        }
        throw new EnumParseException(StaffType.class, String.valueOf(value));
    }

}
